Fix embind exports with MODULARIZE=instance and AUTO_INIT#27414
Open
guybedford wants to merge 1 commit into
Open
Fix embind exports with MODULARIZE=instance and AUTO_INIT#27414guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
guybedford
force-pushed
the
fix-auto-init-embind
branch
from
July 24, 2026 05:36
2e2d59b to
a9024eb
Compare
Collaborator
|
I would hope that we don't need to do this (instead maybe we could make it an assertion if this function is called too late), and we can instread find a way to do the registration before startup. Otherwise we might be tempted to support other event handler beeing registered too late too. @brendandahl WDYT? |
guybedford
force-pushed
the
fix-auto-init-embind
branch
from
July 24, 2026 05:57
18d6d56 to
cefe794
Compare
Collaborator
Author
|
I've updated the approach so postCtor events can only be registered before startup. |
guybedford
force-pushed
the
fix-auto-init-embind
branch
from
July 24, 2026 05:58
cefe794 to
00c19f3
Compare
With AUTO_INIT the embind AOT export snippet was appended after the top-level `await init()`, so its addOnPostCtor callback registered after onPostCtors had already fired, leaving the ES module exports undefined. Emit the snippet via a placeholder ahead of the init logic in the postamble instead, and assert against late addOnPostCtor registration. Fixes emscripten-core#27411
guybedford
force-pushed
the
fix-auto-init-embind
branch
from
July 24, 2026 06:00
00c19f3 to
1beb18d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes embind ES module exports being
undefinedwhen using-sMODULARIZE=instance -sAUTO_INIT -sEMBIND_AOT, resolves #27411.With AUTO_INIT the module self-initializes via top-level
await init()in the postamble, but the embind AOT export snippet was appended after the postamble. ItsaddOnPostCtor(assignEmbindExports)therefore registered only afteronPostCtorshad already fired during init, so the export assignments never ran.Following review feedback, rather than supporting late registration, the snippet is now emitted via a
<<< EMBIND_AOT_EXPORTS >>>placeholder at the start of the MODULARIZE=instance postamble (same mechanism asEMBIND_AOT_INVOKERS), so registration always precedes initialization.addOnPostCtoradditionally asserts under ASSERTIONS that it is not called after ctors have run, rather than silently never firing.Adds
other.test_modularize_instance_auto_init_embindreusingmodularize_instance_embind.cpp, verified to fail before the fix and pass after; existing modularize=instance, ESM integration, dylink and codesize tests still pass (also manually verified WASM_ESM_INTEGRATION + AUTO_INIT + EMBIND_AOT under node 26).Made with AI assistance under my review